package org.yang.common.core.exception;

import lombok.Data;
import org.yang.common.core.enums.REnum;

import java.io.Serial;

/**
 * 自定义全局异常
 * @author: lslands
 * @version: 1.0
 * @create: 2024/5/10
 * @description:
 */
@Data
public class BaseException extends Exception{
    @Serial
    private static final long serialVersionUID = 200901080101009010L;

    public static final int NULL=0;
    /***
     * 冲突
     */
    public static final int REPEAT=1;
    public static final int WARN = 4;
    public static final int ERROR = 5;
    /**
     * 异常方法路径
     */
    protected String path;
    /**
     * 异常等级
     */
    protected int level=5;
    /**
     * 异常代码
     */
    protected int code;
    /**
     * 异常信息
     */
    protected String message;

    public BaseException() {
        super();
        this.code= REnum.ERROR.getCode();
        this.message= REnum.ERROR.getMessage();
        this.level=ERROR;
    }

    public BaseException(String message) {
        super(message);
        this.code= REnum.FAIL.getCode();
        this.level=WARN;
        this.message=message;
    }

    public BaseException(int level) {
        this.code= REnum.FAIL.getCode();
        this.level=level;
    }

    public BaseException(int level,String message) {
        super(message);
        this.code= REnum.FAIL.getCode();
        this.level=level;
        this.message=message;
    }
    public BaseException(String message,String path) {
        super(message);
        this.code= REnum.FAIL.getCode();
        this.level=WARN;
        this.path=path;
    }
    public BaseException(String message, Throwable cause) {
        super(message, cause);
    }

    public BaseException(Throwable cause) {
        super(cause);
    }

}
